<template>
  <div>
    <van-nav-bar :title="info.nickname" right-text="退出" @click-right="onLogout">
      <template #left>
        <van-tag v-if="info.sequence" type="warning">已认证</van-tag>
        <van-tag v-else @click="$router.push('/verify')">未认证</van-tag>
      </template>
    </van-nav-bar>
    <br/>
    <slot></slot>
    <br/>
    <van-cell-group inset>
      <van-cell title="消息订阅" is-link to="/stream"/>
      <van-cell title="编辑资料" is-link to="/info"/>
      <van-cell title="修改密码" is-link to="/password"/>
      <van-cell title="邀请好友" is-link to="/share"/>
      <van-cell title="关于我们" is-link to="/about"/>
    </van-cell-group>
  </div>
</template>

<script>
export default {
  data() {
    return {
      info: {
        sequence: null,
        nickname: '游客',
        username: '未认证'
      }
    }
  },
  methods: {
    load() {
      this.$requests.post('/user/info/obtain').then(resp => {
        this.info = resp
      })
    },
    onLogout() {
      this.$cookies.remove('token');
      localStorage.removeItem('token')
      this.$router.replace('/login')
    }
  },
  mounted() {
    this.load()
  }
}
</script>
